package com.eliza.navs

import org.junit.Test

import org.junit.Assert.*
import kotlin.math.sqrt

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun func() {
        var a = 3
        var b = 6
        var c = 9
        println("$a $b $c")
        sd(a, b, c)

    }

    private fun sd(x: Int, z: Int, y: Int) {


        var k: Double = 0.0
        var j: Double = 0.0


        if (x > 3 && z < 10) {
            k = (x * y - 1).toDouble()
            j = sqrt(k)
        }
        if (x == 4 || y > 5) {
            j = (x * y + 10).toDouble()
            j %= 3
        }
        println("运行结果：：$j")
    }

    @Test
    fun yearTest() {

        var year = 2001
        var month =5
//        println("最大天数："+year(year, month))


//                     4-26          测试用例month=13
//                   4-5-6-7-8-9-26  测试用例month=2,year=2000
//                   4-5-6-7-8-11-26 测试用例month=2,year=2400
//                   4-5-6-7-14-26   测试用例month=2,year=2048
//                   4-5-6-17-26     测试用例month=2,year=2003
//                   4-5-20-21-26    测试用例month=11,year=2000
//                   4-5-20-23-26    测试用例month=3,year=2000


        println("最大天数："+year(year, 13))
        println("最大天数："+year(2000,2))
        println("最大天数："+year(2400,2))
        println("最大天数："+year(2048,2))
        println("最大天数："+year(2003,2))
        println("最大天数："+year(2000,2))
        println("最大天数："+year(2000,3))
    }

    private fun year(year: Int, month: Int): Int {
        var maxday = 0
        if (month in 1..12) {
            if (month == 2) {
                maxday = if (year % 4 == 0) {
                    if (year % 100 == 0) {
                        if (year % 400 == 0) {
                            29
                        } else {
                            28
                        }
                    } else {
                        29
                    }
                } else {
                    28
                }
            } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                maxday = 30

            } else {
                maxday = 31

            }


        }
        return maxday

    }


}